package client;

import java.io.*;
import java.net.*;

public class TestClient {
	
    public static void main(String[] args) throws IOException {

        Socket echoSocket = null;
        PrintWriter out = null;
        BufferedReader in = null;
        String host = "google.ca";

        try {
            echoSocket = new Socket(host, 80);
            out = new PrintWriter(echoSocket.getOutputStream(), true);
            in = new BufferedReader(new InputStreamReader(echoSocket.getInputStream()));
            System.out.println("Connection opened to host: "+host);
        } catch (UnknownHostException e) {
            System.err.println("Don't know about host: "+host);
            System.exit(1);
        } catch (IOException e) {
            System.err.println("Couldn't get I/O for the connection to: "+host);
            System.exit(1);
        }

		BufferedReader stdIn = new BufferedReader(new InputStreamReader(System.in));
		String userInput;
	
		while ((userInput = stdIn.readLine()) != null) {
		    out.println(userInput);
		    System.out.println(in.readLine());
		    if (userInput.equals("exit")) {
		    	System.out.println("Shutting down...");
		    	break;
		    }
		    	
		}
	
		out.close();
		in.close();
		stdIn.close();
		echoSocket.close();
    }
}